package com.sk.cardeal.act.home.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.sk.cardeal.R;
import com.sk.cardeal.act.home.fragment.AlreadyPayFragment;
import com.sk.cardeal.act.home.fragment.AlreadyReachFragment;
import com.sk.cardeal.act.home.fragment.FixingFragment;
import com.sk.cardeal.act.home.fragment.NotExamineFragment;
import com.sk.cardeal.act.home.fragment.NotReachFragment;
import com.sk.cardeal.act.home.fragment.ToVoidFragment;
import com.sk.cardeal.act.home.fragment.TodayOrderFragment;
import com.sk.cardeal.act.home.fragment.WaitPayFragment;
import com.sk.cardeal.act.home.fragment.WaitSendFragment;
import com.sk.cardeal.adapter.MyPagerAdapter;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.view.TitleView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sk on 2017/12/18.
 */

public class OrderManageActivity extends BaseActivity {
    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.my_table)
    TabLayout myTable;
    @BindView(R.id.my_pager)
    ViewPager myPager;


    private List<Fragment> fragmentList = new ArrayList<>();

    TodayOrderFragment todayOrderFragment;
    NotExamineFragment notExamineFragment;
    NotReachFragment notReachFragment;
    AlreadyReachFragment alreadyReachFragment;
    ToVoidFragment toVoidFragment;

    @Override
    protected int getContentView() {
        return R.layout.activity_order_manage;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleView.setMyCallBack(this);
        initFragments();
    }

    private void initFragments() {

        todayOrderFragment = new TodayOrderFragment();
        notExamineFragment = new NotExamineFragment();
        notReachFragment = new NotReachFragment();
        alreadyReachFragment = new AlreadyReachFragment();
        toVoidFragment = new ToVoidFragment();

        fragmentList.add(todayOrderFragment);
        fragmentList.add(notExamineFragment);
        fragmentList.add(notReachFragment);
        fragmentList.add(alreadyReachFragment);
        fragmentList.add(toVoidFragment);

        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), getResources().getStringArray(R.array.order_array), fragmentList);
        myPager.setAdapter(adapter);
        myTable.setupWithViewPager(myPager);
    }

    @Override
    public void clickTitle(int i) {
        super.clickTitle(i);
        switch (i) {
            case 1:
                finish();
                break;
            case 2:
                break;
            case 3:
                Intent intent = new Intent(mContext, NewOrderActivity.class);
                startActivityForResult(intent, 10);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == -1) {
            switch (requestCode) {
                case 10:
                    notExamineFragment.doRefresh();
                    break;
                case 20:
                    notExamineFragment.doRefresh();
                    notReachFragment.doRefresh();
                    alreadyReachFragment.doRefresh();
                    toVoidFragment.doRefresh();
                    break;
            }
        }
    }
}
